home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performCreateRenderLayer.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  10.7 KB  |  428 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  October 30, 1998
  22. //  Author:         Socrates
  23. //
  24. //  Description:
  25. //
  26. // An option window used to create a named renderLayer.
  27. // A renderLayer is a grouping of DAG objects used to control drawing.
  28. //
  29.  
  30. //
  31. //  Procedure Name:
  32. //      setOptionVars
  33. //
  34. //  Description:
  35. //        Initialize the option values.
  36. //
  37. //  Input Arguments:
  38. //        Whether to set the options to default values.
  39. //
  40. //  Return Value:
  41. //      None.
  42. //
  43. proc setOptionVars(int $forceFactorySettings)
  44. {
  45.     //    Render layer base index
  46.     //
  47.     if ($forceFactorySettings || !`optionVar -exists renderLayerBase`) {
  48.         optionVar -intValue renderLayerBase 1;
  49.     }
  50.  
  51.     //    Set to Current flag
  52.     //
  53.     if ($forceFactorySettings || !`optionVar -exists renderLayerCurrent`) {
  54.         optionVar -intValue renderLayerCurrent false;
  55.     }
  56.  
  57.     //    Contents flag
  58.     //
  59.     if ($forceFactorySettings || !`optionVar -exists renderLayerContents`) {
  60.         optionVar -intValue renderLayerContents 1;
  61.     }
  62. }
  63.  
  64. //
  65. //  Procedure Name:
  66. //      createRenderLayerSetup
  67. //
  68. //  Description:
  69. //        Update the state of the option box UI to reflect the option values.
  70. //
  71. //  Input Arguments:
  72. //      parent               - Top level parent layout of the option box UI.
  73. //                             Required so that UI object names can be 
  74. //                             successfully resolved.
  75. //
  76. //    forceFactorySettings - Whether the option values should be set to
  77. //                             default values.
  78. //
  79. //  Return Value:
  80. //      None.
  81. //
  82. global proc createRenderLayerSetup(string $parent, int $forceFactorySettings)
  83. {
  84.     // Retrieve the option settings
  85.     //
  86.     setOptionVars( $forceFactorySettings );
  87.     
  88.     // Layer name
  89.     textFieldGrp -e -text "layer1" renderLayerNameWidget;    
  90.  
  91.     // Base layer index
  92.     int $base = `optionVar -q renderLayerBase`;
  93.     intFieldGrp -e -v1 $base renderLayerBaseWidget;    
  94.  
  95.     // Contents flag
  96.     int $contents = `optionVar -q renderLayerContents`;
  97.     radioButtonGrp -e -sl $contents contentsRadio;
  98.  
  99.     // Set to Current flag
  100.     int $current = `optionVar -q renderLayerCurrent`;
  101.     checkBoxGrp -e -v1 $current currentCheck;
  102.  
  103.     setParent $parent;
  104. }
  105.  
  106. //
  107. //  Procedure Name:
  108. //      createRenderLayerCallback
  109. //
  110. //  Description:
  111. //        Update the option values with the current state of the option box UI.
  112. //
  113. //  Input Arguments:
  114. //      parent - Top level parent layout of the option box UI.  Required so
  115. //               that UI object names can be successfully resolved.
  116. //
  117. //    doIt   - Whether the command should execute.
  118. //
  119. //  Return Value:
  120. //      None.
  121. //
  122. global proc createRenderLayerCallback(string $parent, int $doIt)
  123. {
  124.     setParent $parent;
  125.  
  126.     //    Contents flag
  127.     //
  128.     optionVar -iv renderLayerContents `radioButtonGrp -q -sl contentsRadio`;
  129.  
  130.     //    'Make current' flag
  131.     //
  132.     optionVar -iv renderLayerCurrent `checkBoxGrp -q -v1 currentCheck`;
  133.  
  134.     //    Base layer index
  135.     //
  136.     optionVar -iv renderLayerBase `intFieldGrp -q -v1 renderLayerBaseWidget`;
  137.  
  138.     if ($doIt) {
  139.         performCreateRenderLayer 0; 
  140.         addToRecentCommandQueue "performCreateRenderLayer 0" "CreateRenderLayer";
  141.     }
  142. }
  143.  
  144. //
  145. //  Procedure Name:
  146. //      createRenderLayerOptions
  147. //
  148. //  Description:
  149. //        Construct the option box UI.  Involves accessing the standard option
  150. //        box and customizing the UI accordingly.
  151. //
  152. //  Input Arguments:
  153. //      None.
  154. //
  155. //  Return Value:
  156. //      None.
  157. //
  158. proc createRenderLayerOptions()
  159. {
  160.     //    Name of the command for this option box.
  161.     //
  162.     string $commandName = "createRenderLayer";
  163.  
  164.     //    Build the option box actions.
  165.     //
  166.     string $callback = ($commandName + "Callback");
  167.     string $setup = ($commandName + "Setup");
  168.  
  169.     //    STEP 1:  Get the option box.
  170.     //    ============================
  171.     //
  172.     //    The value returned is the name of the layout to be used as
  173.     //    the parent for the option box UI.
  174.     //
  175.     string $layout = getOptionBox();
  176.     setParent $layout;
  177.     
  178.     //    STEP 2:  Pass the command name to the option box.
  179.     //    =================================================
  180.     //
  181.     //    Any default option box behaviour based on the command name is set 
  182.     //    up with this call.  For example, updating the 'Help' menu item with
  183.     //    the name of the command.
  184.     //
  185.     setOptionBoxCommandName($commandName);
  186.     
  187.     //    STEP 3:  Activate the default UI template.
  188.     //    ==========================================
  189.     //
  190.     //    Activate the default UI template so that the layout of this 
  191.     //    option box is consistent with the layout of the rest of the 
  192.     //    application.
  193.     //
  194.     setUITemplate -pushTemplate DefaultTemplate;
  195.  
  196.     //    STEP 4: Create option box contents.
  197.     //    ===================================
  198.     
  199.     //    Turn on the wait cursor.
  200.     //
  201.     waitCursor -state 1;
  202.  
  203.     tabLayout -tabsVisible 0 -scrollable 1;
  204.     string $parent = `columnLayout -adjustableColumn 1`;
  205.     string $tabForm = `columnLayout -adjustableColumn true`;
  206.  
  207.     // renderLayer name
  208.     //
  209.     textFieldGrp
  210.         -label "Name"
  211.         renderLayerNameWidget;    
  212.  
  213.     // renderLayer number
  214.     //
  215.     intFieldGrp
  216.         -label "Number"
  217.         renderLayerBaseWidget;    
  218.  
  219.     // Current layer setting option
  220.     //
  221.     checkBoxGrp -numberOfCheckBoxes 1
  222.         -label1 "Make the created render layer current"
  223.         currentCheck;
  224.  
  225.     // Which items to add to the layer
  226.     //
  227.     radioButtonGrp -nrb 3
  228.         -cw 2 80
  229.         -cw 4 160
  230.         -l "Add to new render layer" 
  231.         -la3 "Nothing" "Selected" "Selected and Children"
  232.         -sl (`optionVar -q renderLayerContents`)
  233.         -cc1 "optionVar -iv renderLayerContents 1"
  234.         -cc2 "optionVar -iv renderLayerContents 2"
  235.         -cc3 "optionVar -iv renderLayerContents 3"
  236.         contentsRadio;
  237.  
  238.     //    Turn off the wait cursor.
  239.     //
  240.     waitCursor -state 0;
  241.     
  242.     //    Step 5: Deactivate the default UI template.
  243.     //    ===========================================
  244.     //
  245.     setUITemplate -popTemplate;
  246.  
  247.     //    Step 6: Customize the buttons.  
  248.     //    ==============================
  249.     //
  250.     //    Provide more descriptive labels for the buttons.  This is not 
  251.     //    necessary, but in some cases, for example, a button labelled 
  252.     //    'Create' may be more meaningful to the user than one labelled
  253.     //    'Apply'.
  254.     //
  255.     //    Disable those buttons that are not applicable to the option box.
  256.     //
  257.     //    Attach actions to those buttons that are applicable to the option
  258.     //    box.  Note that the 'Close' button has a default action attached 
  259.     //    to it that will hide the window.  If a a custom action is
  260.     //    attached to the 'Close' button then be sure to call the 'hide the
  261.     //    option box' procedure within the custom action so that the option
  262.     //    box is hidden properly.
  263.  
  264.     //    'Apply' button.
  265.     //
  266.     string $applyBtn = getOptionBoxApplyBtn();
  267.     button -edit
  268.         -label "Create"
  269.         -command ($callback + " " + $parent + " " + 1)
  270.         $applyBtn;
  271.  
  272.     //    'Save' button.
  273.     //
  274.     string $saveBtn = getOptionBoxSaveBtn();
  275.     button -edit 
  276.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  277.         $saveBtn;
  278.  
  279.     //    'Reset' button.
  280.     //
  281.     string $resetBtn = getOptionBoxResetBtn();
  282.     button -edit 
  283.         -command ($setup + " " + $parent + " " + 1)
  284.         $resetBtn;
  285.  
  286.     //    Step 7: Set the option box title.
  287.     //    =================================
  288.     //
  289.     setOptionBoxTitle("Render Layer Options");
  290.  
  291.     //    Step 8: Customize the 'Help' menu item text.
  292.     //    ============================================
  293.     //
  294.     setOptionBoxHelpTag( "" );
  295.  
  296.     //    Step 9: Set the current values of the option box.
  297.     //    =================================================
  298.     //
  299.     eval (($setup + " " + $parent + " " + 0));    
  300.     
  301.     //    Step 10: Show the option box.
  302.     //    =============================
  303.     //
  304.     showOptionBox();
  305. }
  306.  
  307. //
  308. //  Procedure Name:
  309. //      createRenderLayerHelp
  310. //
  311. //  Description:
  312. //        Return a short description about this command.
  313. //
  314. //  Input Arguments:
  315. //      None.
  316. //
  317. //  Return Value:
  318. //      string.
  319. //
  320. proc string createRenderLayerHelp()
  321. {
  322.  
  323.     return 
  324.     "  Command: Create Render Layer - create a renderLayer.\n" +
  325.     "Selection: Selected DAG objects are added to the renderLayer.";
  326. }
  327.  
  328. //
  329. //  Procedure Name:
  330. //      assembleCmd
  331. //
  332. //  Description:
  333. //        Construct the command that will apply the option box values.
  334. //
  335. //  Input Arguments:
  336. //      None.
  337. //
  338. proc string assembleCmd()
  339. {
  340.     string $cmd;
  341.  
  342.     setOptionVars(false);
  343.  
  344.     // get the renderLayer name
  345.     string $renderLayerName = "layer1";
  346.     if (`textFieldGrp -exists renderLayerNameWidget`) {
  347.         $renderLayerName = `textFieldGrp -q -text renderLayerNameWidget`;
  348.     }
  349.  
  350.     // get the renderLayer base number
  351.     int $renderLayerBase = `optionVar -q renderLayerBase`;
  352.  
  353.     // create the renderLayer command string
  354.     if (0 == size($renderLayerName)) {
  355.         $renderLayerName = "layer1";
  356.     }
  357.     $renderLayerName = "\"" + $renderLayerName + "\"";
  358.     $cmd = "createRenderLayer -name " + $renderLayerName
  359.                      + " -number " + $renderLayerBase;
  360.  
  361.     int $contents = `optionVar -q renderLayerContents`;
  362.     int $current = `optionVar -q renderLayerCurrent`;
  363.     if( $contents == 1 )
  364.     {
  365.         $cmd += " -empty";
  366.     }
  367.     else if( $contents == 2 )
  368.     {
  369.         $cmd += " -nr";
  370.     }
  371.     if( $current ) $cmd += " -mc";
  372.  
  373.     return $cmd;
  374. }
  375.  
  376. //
  377. //  Procedure Name:
  378. //      performCreateRenderLayer
  379. //
  380. //  Description:
  381. //        Perform the create render layer command using the corresponding 
  382. //        option values.  This procedure will also show the option box
  383. //        window if necessary as well as construct the command string
  384. //        that will invoke the createRenderLayer command with the current
  385. //        option box values.
  386. //
  387. //  Input Arguments:
  388. //      0 - Execute the command.
  389. //      1 - Show the option box dialog.
  390. //      2 - Return the command.
  391. //
  392. global proc string performCreateRenderLayer(int $action)
  393. {
  394.     string $cmd = "";
  395.  
  396.     switch ($action) {
  397.  
  398.         //    Execute the command.
  399.         //
  400.         case 0:
  401.             //    Get the command.
  402.             //
  403.             $cmd = `assembleCmd`;
  404.  
  405.             //    Execute the command with the option settings.
  406.  
  407.             evalEcho($cmd);
  408.  
  409.             break;
  410.  
  411.         //    Show the option box.
  412.         //
  413.         case 1:
  414.             createRenderLayerOptions;
  415.             break;
  416.  
  417.         //    Return the command string.
  418.         //
  419.         case 2:
  420.             //    Get the command.
  421.             //
  422.             $cmd = `assembleCmd`;
  423.             break;
  424.     }
  425.     return $cmd;
  426. }
  427.  
  428.